%option noinput
%option nounput
%{
    #include "fonctions.h"
    #include "y.tab.h"
    int ligne = 1;
    #define TYPE_BOOL 0
    #define TYPE_INT 1
    #define TYPE_UNIT 2
%}

lettre              [a-zA-Z]
chiffre             [0-9]

%%

"program"                           return _program;
"var"                               return _var;
"unit"                              yylval.type = TYPE_UNIT; return _type;
"bool"                              yylval.type = TYPE_BOOL; return _type;
"int"                               yylval.type = TYPE_INT; return _type;
"array"                             return _array;
"of"                                return _of;
".."                                return _range;
"function"                          return _function;
"["|"]"|"("|")"|","|";"|":"         return yytext[0];
"ref"                               return _ref;
"if"                                return _if;
"then"                              return _then;
"else"                              return _else;
"while"                             return _while;
"do"                                return _do;
":="                                return _affect;
"return"                            return _return;
"begin"                             return _begin;
"end"                               return _end;
"read"                              return _read;
"write"                             return _write;
"writeln"                           return _writeln;
"+"|"-"|"*"|"/"|"^"|"<"|">"|"="     return yytext[0];
">="                                return _gt;
"<="                                return _lt;
"<>"                                return _ne;
"and"                               return _and;
"or"                                return _or;
"xor"                               return _xor;
"not"                               return _not;

"true"                              { yylval.val = (1==1); return _cst_bool;}
"false"                             { yylval.val = (1==0); return _cst_bool;}
[0-9][0-9]*                         { yylval.val = atoi(yytext); return _cst_int;}
\"[^"]*\"                           { yylval.vals = strdup(yytext); return _cst_string; }

{lettre}({lettre}|{chiffre}|"_")*   {yylval.id = strdup(yytext); return _ident;}
" "|[\t]
\n                                  {ligne++;}
"(*".*"*)"                          
.                                   { printf("Erreur : caractère inconnu : %s\n", yytext); exit(-1);}

%%
